package com.zahb.qadx.ui.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zahb.qadx.R;
import com.zahb.qadx.model.MainFunc1;
import com.zahb.qadx.model.MainFunc2;
import com.zahb.qadx.util.CompatHelper;
import com.zahb.qadx.util.ImageLoaderKt;
import com.zahb.qadx.util.Time;

import org.jetbrains.annotations.NotNull;

/**
 * Created by Zdw on 2020/10/13 16:33
 * 今日之星
 */
public class TodayStarFragment extends StarTeacherFragment {

    static final String TAG = "TodayStarFragment";

    static TodayStarFragment newInstance(MainFunc1 mainFunc1) {
        Bundle args = new Bundle();
        args.putSerializable("data", mainFunc1);
        TodayStarFragment fragment = new TodayStarFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mTvTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
                R.drawable.ic_trophy, 0, 0, 0);
        view.findViewById(R.id.tv_see_more).setVisibility(View.GONE);
    }

    @NonNull
    @Override
    protected BaseQuickAdapter<MainFunc2, BaseViewHolder> getAdapter() {
        mAdapter = new TodayStarAdapter(R.layout.item_list_today_star);
        return mAdapter;
    }

    public static class TodayStarAdapter extends BaseQuickAdapter<MainFunc2, BaseViewHolder> {

        TodayStarAdapter(int layoutResId) {
            super(layoutResId);
        }

        @Override
        protected void convert(@NotNull BaseViewHolder baseViewHolder, MainFunc2 mainFunc2) {
            ImageLoaderKt.loadImageCircle(baseViewHolder.getView(R.id.iv_icon), mainFunc2.getIcon(), R.drawable.ic_default_portrait);
            baseViewHolder
                    .setText(R.id.tv_name, mainFunc2.getTitle())
                    .setText(R.id.tv_desc, CompatHelper.isEmpty(mainFunc2.getSubTitle())
                            ? "部门待完善" : mainFunc2.getSubTitle());
            switch (baseViewHolder.getAdapterPosition()){
                case 0:
                    baseViewHolder.setImageResource(R.id.iv_pos, R.drawable.ic_first);
                    baseViewHolder.setText(R.id.tv_count, CompatHelper.isEmpty(mainFunc2.getUserNum())
                            ? Time.setTimes(500) + "" : mainFunc2.getUserNum());
                    break;
                case 1:
                    baseViewHolder.setImageResource(R.id.iv_pos, R.drawable.ic_second);
                    baseViewHolder.setText(R.id.tv_count, CompatHelper.isEmpty(mainFunc2.getUserNum())
                            ? Time.setTimes(300) + "" : mainFunc2.getUserNum());
                    break;
                case 2:
                    baseViewHolder.setImageResource(R.id.iv_pos, R.drawable.ic_third);
                    baseViewHolder.setText(R.id.tv_count, CompatHelper.isEmpty(mainFunc2.getUserNum())
                            ? Time.setTimes(200) + "" : mainFunc2.getUserNum());
                    break;

            }

        }
    }
}
